
public class p1011_1_204ms {

	public static//
	// -----
	// -----
	class Main {
		public static void main(String[] args) throws Exception {
			java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
			while (true) {
				if (Integer.parseInt(reader.readLine()) == 0)
					return;
				String[] parts = reader.readLine().split(" ");
				int[] nums = new int[parts.length];
				for (int i = 0; i < nums.length; i++)
					nums[i] = Integer.parseInt(parts[i]);
				java.util.Arrays.sort(nums);
				System.out.println(process(nums));
			}
		}

		static int process(int[] nums) {
			int sum = 0;
			for (int i : nums)
				sum += i;
			int[][] stat = stat(nums);
			for (width = nums[nums.length - 1]; width < sum; width++) {
				if (sum % width == 0 && possible(stat, stat.length - 1, 0, 0))
					return width;
			}
			return sum;
		}

		static int[][] stat(int[] nums) {
			java.util.List<int[]> stat = new java.util.ArrayList<int[]>();
			int val = nums[0], count = 0;
			for (int v : nums) {
				if (v == val) {
					count++;
				} else {
					stat.add(new int[] { val, count });
					val = v;
					count = 1;
				}
			}
			stat.add(new int[] { val, count });
			int[][] result = new int[stat.size()][];
			for (int i = 0; i < result.length; i++)
				result[i] = stat.get(i);
			return result;
		}

		static int width;

		static boolean possible(int[][] stats, int maxStat, int left, int maxLeftId) {
			if (left == 0) {
				while (maxStat >= 0 && stats[maxStat][1] == 0)
					maxStat--;
				if (maxStat < 0)
					return true;
				stats[maxStat][1]--;
				if (possible(stats, maxStat, width - stats[maxStat][0], maxStat))
					return true;
				stats[maxStat][1]++;
			} else if (left > 0) {
				for (int i = maxLeftId; i >= 0; i--) {
					if (stats[i][0] > left || stats[i][1] <= 0)
						continue;
					stats[i][1]--;
					if (possible(stats, maxStat, left - stats[i][0], i))
						return true;
					stats[i][1]++;
				}
			}
			return false;
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
